package com.hualan.servlet;

import com.alibaba.fastjson.JSON;
import com.hualan.dao.CourierStationDao;
import com.hualan.dao.impl.CourierStationDaoImp;
import com.hualan.bean.PanghuCourierStation;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/updatePcs")
public class updateServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        CourierStationDao csdao=new CourierStationDaoImp();
        //接收传递的数据
        String courierStationName=req.getParameter("courierStationName");
        String courierStationImage=req.getParameter("courierStationImage");
        String courierStationProvince= req.getParameter("courierStationProvince");
        String courierStationCity=req.getParameter("courierStationCity");
        String courierStationDistrict=req.getParameter("courierStationDistrict");
        String courierStationAddress=req.getParameter("courierStationAddress");
        String courierStationId1=req.getParameter("courierStationId");
        int courierStationId=Integer.parseInt(courierStationId1);
        System.out.println(courierStationName+courierStationImage+courierStationProvince);
        //创建对象并且给对象赋值
        PanghuCourierStation p1=new PanghuCourierStation();
        p1.setCourierStationName(courierStationName);
        p1.setCourierStationImage(courierStationImage);
        p1.setCourierStationProvince(courierStationProvince);
        p1.setCourierStationCity(courierStationCity);
        p1.setCourierStationDistrict(courierStationDistrict);
        p1.setCourierStationAddress(courierStationAddress);
        p1.setCourierStationId(courierStationId);
        //创建map用来返回值
        Map<String,Object> map=new HashMap<>();
        System.out.println(p1);
        int row=csdao.updatePcs(p1);
        if (row<1){
            map.put("code",302);
            map.put("message","修改失败");
        }else {
            map.put("code",200);
            map.put("message","修改成功！");
        }
        resp.getWriter().write(JSON.toJSONString(map));
    }
}
